<%@page import="net.pws.oos.security.SecurityUtils"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../header.jsp"%>

<script type="text/javascript" src="<%=ctx%>/js/jquery.bootstrap-carousel.js"></script>
<script type="text/javascript" src="<%=ctx%>/js/jquery.bootstrap-transition.js"></script>
<script type="text/javascript">
var prospectLoaded = false;

function loadTaskDetail(){
	if ($("#detailPanel").data("loaded")) {
		return;
	}
	 
	var status = $("#taskStatus").data("code");
	if("completed" != status){
// 		$("#resultForm").hide();
// 		$("#resultNotExistsDiv").show();
		return;
	}
	
// 	$("#resultForm").show();
// 	$("#resultNotExistsDiv").hide();

// 	var taskId = $("#taskId").val();
// 	$.ajax({
// 		type: "GET",
// 		cache: false,
// 		url: "result/detail.json?taskId=" + taskId,
// 		dataType: "json",
// 		success: loadResultSucceedCallback,
// 		error:function(message){
// 			$.alert(message);
// 		}  
// 	});	

	$("#detailPanel").data("loaded",true);
}

// function loadSupervByTask(){
// 	if ($("#supervPanel").data("loaded")) {
// 		return;
// 	}
	
// 	var status = $("#taskStatus").data("code");
// 	if("completed" != status){
// 		$("#supervCarousel").hide();
// 		$("#supervNotWritedAbleDiv").show();
// 		return;
// 	}
	
// 	$("#supervCarousel").show();
// 	$("#supervNotWritedAbleDiv").hide();
	
// 	var taskId = $("#taskId").val();
// 	$.ajax({
// 		type: "GET",
// 		cache: false,
// 		url: "superv/list.json?taskId=" + taskId,
// 		dataType: "json",
// 		success: loadSupervSucceedCallback,
// 		error:function(message){
// 			$.alert(message);
// 		}
// 	});

// 	$("#supervPanel").data("loaded",true);
// }

function loadProspectByTask(){
	if(prospectLoaded){
		return;
	}
	prospectLoaded = true;
	
	var taskId = $("#taskId").val();
// 	var prospectRecodId = $("#prospectRecodId").val();
	$.ajax({
		type: "GET",
		cache: false,
// 		url: "prospect/detail.json?id="+prospectRecodId+"&taskId=" + taskId,
		url: "prospect/detail.json?taskId=" + taskId,
		dataType: "json",
		success: loadProspectSucceedCallback,
		error:function(message){
			$.alert(message);
		}
	});
}

function loadPhotosByTask(){
	if ($("#photoPanel").data("loaded")) {
		return;
	}
	
	var status = $("#taskStatus").data("code");
	if("completed" != status){
		$("#photoCarousel").hide();
		$("#photoNotExistsDiv").show();
		return;
	}
	
	$("#photoCarousel").show();
	$("#photoNotExistsDiv").hide();
	
	var taskId = $("#taskId").val();
	$.ajax({
		type: "GET",
		cache: false,
		url: "attachment/list.json?resourceId=" + taskId,
		dataType: "json",
		success: loadPhotosSucceedCallback,
		error:function(message){
			$.alert(message);
		}
	});

	$("#photoPanel").data("loaded",true);
}

function loadSubTasks() {
	if ($("#subTaskPanel").data("loaded")) {
		return;
	}
	
	initSubTaskList();

	$("#subTaskPanel").data("loaded",true);
}

function loadTaskMap() {
	if ($("#mapPanel").data("loaded")) {
		return;
	}
	
	initMap();

	$("#mapPanel").data("loaded",true);
}

//导出word文档
function word(){
	var photoData = $("input[id=photoDescription]");
	if(photoData.length > 0){
		var validateResult = "";
		$(photoData).each(function(i, item) {
			if(item.defaultValue != item.value){
				validateResult += "第" + (i+1) + "张现场照片描述信息未保存 \n";
			}			
		});
		if(validateResult != ""){
			validateResult += "确认要继续导出吗？";
			if (!confirm(validateResult)) {
				return;
			}
		}
		
	}
	location.href="word.do?id=${id}";
}


$(document).ready(function() {
//	$("#tabs").tab("show");
	$('a[data-toggle="tab"]').on('shown', function (e) {
		var actived = $(e.target).attr("href");
// 		if(actived == "#resultPanel"){
		if(actived == "#detailPanel"){
			loadTaskDetail();			
		} else if(actived == "#supervPanel"){
// 			loadSupervByTask();
			loadProspectByTask();
		} else if(actived == "#photoPanel"){
			loadPhotosByTask();
		} else if (actived == "#subTaskPanel") {
			loadSubTasks();
		} else if (actived == "#mapPanel") {
			loadTaskMap();
		}
		
	});
});
</script>

<div class="border bg">

<div class="page-header">
	<h2>查看任务<small id="taskTitle"></small></h2>
	<div class="cms_toolbar">
		<a id="exportButton" href="javascript:word()" class="btn hide"><i class="icon-share"></i>导出</a>
		<% if(SecurityUtils.allowedResource("/task/dispatch/to_progress")){ %>
		<a id="progressButton" href="javascript:toProgress()" class="btn btn-danger hide"><i class="icon-bookmark"></i>设为处理中</a>
		<%} 
		  if(SecurityUtils.allowedResource("/task/dispatch/to_assigned")){
		%>
		<a id="assignedButton" href="javascript:toAssigned()" class="btn btn-danger hide"><i class="icon-file"></i>设为待办</a>
		<%} 
		  if(SecurityUtils.allowedResource("/task/dispatch/to_assigned")){
		%>
		<a id="cleanButton" href="javascript:cleanAddress()" class="btn btn-info"><i class="icon-refresh"></i>重置地址</a>
		<%} %>
	</div>
</div>


<div id="tabs">
<ul class="nav nav-tabs">
<li class="active"><a href="#detailPanel" data-toggle="tab">基本信息</a></li>
<li><a href="#supervPanel" data-toggle="tab">项目情况</a></li>
<li><a href="#photoPanel" data-toggle="tab">现场照片<small id="photoIndex"></small></a></li>
<li><a href="#mapPanel" data-toggle="tab">现场地图</a></li>
</ul>

<div class="tab-content">
<div id="detailPanel" class="tab-pane fade in active">
	<%@ include file="detail.detail.jsp"%>
</div>

<div id="supervPanel" class="tab-pane fade">
	<jsp:include page="detail.prospect.jsp"/>
<!-- 	<div class="well" id="supervNotWritedAbleDiv"> -->
<!-- 		此任务未完成，尚未有项目情况信息！ -->
<!-- 	</div> -->
</div>

<div id="photoPanel" class="tab-pane fade">
	<jsp:include page="detail.photo.jsp"/>
	<div class="well" id="photoNotExistsDiv">
		此任务未完成，尚未有照片信息！
	</div>
</div>

<div id="mapPanel" class="tab-pane fade">
	<jsp:include page="detail.map.jsp"/>
</div>

</div>
</div>

</div>


<%@ include file="../../footer.jsp"%>